<template>
    <div>
        <attribute-tabs title="开屏广告">
            <div>
                <el-form ref="form" label-width="80px" size="small" label-position="left">
                    <attribute-item title="是否启用">
                        <el-form-item label-width="0">
                            <el-switch v-model="content.enable" active-value="1" inactive-value="0">
                            </el-switch>
                        </el-form-item>
                    </attribute-item>
                    <attribute-item
                        title="广告内容"
                        desc="最多添加5张广告图，建议图片尺寸：1080px*1920px"
                    >
                        <div class="nav-list">
                            <draggable v-model="content.data" animation="300">
                                <div
                                    class="nav-item ls-del-wrap"
                                    v-for="(item, index) in content.data"
                                    :key="index"
                                >
                                    <div class="flex">
                                        <material-select
                                            ref="materialSelect"
                                            v-model="item.url"
                                            :size="48"
                                            upload-bg="#fff"
                                        >
                                            <i class="el-icon-plus"></i>
                                        </material-select>
                                        <div class="m-l-10">
                                            <link-select v-model="item.link" />
                                        </div>
                                    </div>
                                    <i
                                        @click="onDelete(index)"
                                        class="el-icon-close ls-icon-del"
                                    ></i>
                                </div>
                            </draggable>
                        </div>
                        <el-form-item label-width="0">
                            <el-button
                                size="small"
                                v-if="content.data.length < 5"
                                class="add-nav"
                                @click="onAdd"
                                >+ 添加{{ content.data.length }}/5</el-button
                            >
                        </el-form-item>
                    </attribute-item>
                </el-form>
            </div>
        </attribute-tabs>
    </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import AttributeTabs from '@/components/decorate/attribute-tabs.vue'
import ColorSelect from '@/components/decorate/color-select.vue'
import StyleChose from '@/components/decorate/style-chose.vue'
import Slider from '@/components/decorate/slider.vue'
import AttributeItem from '@/components/decorate/attribute-item.vue'
import LinkSelect from '@/components/link-select/index.vue'
import MaterialSelect from '@/components/material-select/index.vue'
import Draggable from 'vuedraggable'
@Component({
    components: {
        AttributeTabs,
        ColorSelect,
        StyleChose,
        Slider,
        AttributeItem,
        MaterialSelect,
        LinkSelect,
        Draggable
    }
})
export default class Attribute extends Vue {
    @Prop() content!: any
    @Prop() styles!: any
    /** S data **/
    $refs!: { materialSelect: any }
    /** E data **/

    /** S computed **/

    /** E computed **/

    /** S methods **/
    onAdd() {
        if (this.content.data.length > 5) {
            return this.$message.warning('最多五张图片')
        }
        this.content.data.push({
            url: '',
            link: {}
        })
    }
    onDelete(index: number) {
        this.content.data.splice(index, 1)
    }
    /** E methods **/
}
</script>

<style lang="scss" scoped>
.nav-list {
    .nav-item {
        background: #f9f9f9;
        padding: 20px;
        margin-bottom: 20px;
        cursor: move;
        &.forbid {
            cursor: unset;
        }
    }
}
.add-nav {
    width: 100%;
}
</style>
